package com.rainng.coursesystem.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rainng.coursesystem.model.bo.StudentCourseItemBO;
import com.rainng.coursesystem.model.entity.StudentCourseEntity;
import com.rainng.coursesystem.model.vo.response.table.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface StudentCourseMapper extends BaseMapper<StudentCourseEntity> {

    Integer count(@Param("className")String className, @Param("courseName")String courseName, @Param("studentName")String studentName);

    IPage<StudentCourseItemVO> getPage(IPage<StudentCourseItemVO> page, @Param("className")String className, @Param("courseName")String courseName,@Param("studentName") String studentName);

    Integer countTeacherGrade(@Param("teacherId")Integer teacherId,@Param("courseName") String courseName,@Param("studentName") String studentName);

    IPage<TeacherGradeItemVO> getTeacherGradePage(IPage<TeacherGradeItemVO> page, @Param("teacherId")Integer teacherId, @Param("courseName")String courseName,@Param("studentName") String studentName);

    List<StudentCourseSelectedItemVO> listStudentCourseSelected(Integer studentId);

    List<StudentExamItemVO> listStudentExam(Integer studentId);

    Integer countStudentCourseSelectedByTimePart(@Param("studentId")Integer studentId,@Param("timePart") String timePart);

    List<TimetableItemVO> listStudentTimetable(Integer studentId);

    List<StudentCourseEntity> getByStatusAndTeacherId(@Param("status") Integer status, @Param("teacherId") Integer teacherId);

    @Select("SELECT sc.sc_id AS id, s.student_name AS studentName, " +
            "co.course_name AS courseName, " +
            "sc.sc_status AS status, sc.sc_audit_time AS auditTime, " +
            "sc.sc_audit_teacher_id AS auditTeacherId " +
            "FROM rc_student_course sc " +
            "JOIN rc_student s ON sc.sc_student_id = s.student_id " +
            "JOIN rc_course co ON sc.sc_course_id = co.course_id " +
            "WHERE co.course_teacher_id = #{teacherId} " )
    Page<StudentCourseItemBO> getTeacherStudentCoursePage(
            Page<StudentCourseItemBO> page,
            @Param("teacherId") Integer teacherId,
            @Param("studentName") String studentName,
            @Param("courseName") String courseName,
            @Param("status") Integer status);
}
